﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KulaQ.Models;
using KulaQ.Helpers;
using KulaQ.Models.Entities;

namespace KulaQ.Controllers
{
    public class AudienceController : Controller
    {
        AdventureWorksDB db = new AdventureWorksDB();

        DmxHelper dmm = new DmxHelper();

        //
        // GET: /DM/

        public ActionResult Index()
        {
            var viewModel = new AudienceModel();

            viewModel.PredictableList = new List<object>();

            foreach (var attr in typeof(TargetMail).GetProperties())
            {
                viewModel.PredictableList.Add(new { Value = attr.Name, Text = attr.Name });
            }

            return View(viewModel);
        }

        [HttpPost]
        public ActionResult Index(AudienceModel viewModel)
        {
            if (viewModel.Predictable == "BikeBuyer")
            {
                return RedirectToAction("Predict");
            }
            else
            {
                return View(viewModel);
            }
        }

        public ActionResult Predict()
        {
            PredictionModel resultTable = dmm.DmxQuery();

            return View(resultTable);
        }
    }
}
